#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 
# Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
# 

"""
File: run11.py
Author: zhangyang(zhangyang40@baidu.com)
Date: 2018/1/5 0005 13:58
"""
"""
输入一个链表，反转链表后，输出链表的所有元素
"""


class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None


class Solution:
    # 返回ListNode
    def ReverseList(self, pHead):
        if pHead is None:
            return None
        newHead = None
        pNode = pHead
        pPrev = None

        while pNode is not None:
            pNext = pNode.next
            if pNode is None:
                newHead = pHead
            pNode.next = pPrev
            pPrev = pNode
            pNode = pNext
        return newHead
